package com.easyadmin.modules.stock.controller;

import com.easyadmin.common.aop.annotation.Repeat;
import com.easyadmin.common.web.base.BaseController;
import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.common.web.domain.response.Result;
import com.easyadmin.common.web.domain.response.module.ResultTable;
import com.easyadmin.modules.stock.domain.SysStockMa;
import com.easyadmin.modules.stock.service.ISysStockMaService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 均线分析Controller
 *
 * @author jmys
 * @date 2025-10-02
 */
@RestController
@RequestMapping("/stock/stockMa")
public class SysStockMaController extends BaseController {

    private String prefix = "stock/stockMa";

    @Autowired
    private ISysStockMaService sysStockMaService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/stock/stockMa/main','stock:stockMa:main')")
    public ModelAndView main() {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询均线分析列表
     */
    @ResponseBody
    @GetMapping("/data")
    @ApiOperation(value = "查询均线分析列表")
    @PreAuthorize("hasPermission('/stock/stockMa/data','stock:stockMa:data')")
    public ResultTable list(@ModelAttribute SysStockMa sysStockMa, PageDomain pageDomain) {
        PageInfo<SysStockMa> pageInfo = sysStockMaService.selectSysStockMaPage(sysStockMa, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }

    /**
     * 新增均线分析
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/stock/stockMa/add','stock:stockMa:add')")
    public ModelAndView add() {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增均线分析
     */
    @Repeat
    @PostMapping("/save")
    @ApiOperation(value = "新增均线分析")
    @PreAuthorize("hasPermission('/stock/stockMa/add','stock:stockMa:add')")
    public Result save(@RequestBody SysStockMa sysStockMa) {
        return decide(sysStockMaService.save(sysStockMa));
    }

    /**
     * 修改均线分析
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/stock/stockMa/edit','stock:stockMa:edit')")
    public ModelAndView edit(Long id, ModelMap map) {
        SysStockMa sysStockMa =sysStockMaService.getById(id);
        map.put("sysStockMa", sysStockMa);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改均线分析
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改均线分析")
    @PreAuthorize("hasPermission('/stock/stockMa/edit','stock:stockMa:edit')")
    public Result update(@RequestBody SysStockMa sysStockMa) {
        return decide(sysStockMaService.update(sysStockMa));
    }

    /**
     * 删除均线分析
     */
    @DeleteMapping("/batchRemove")
    @ApiOperation(value = "删除均线分析")
    @PreAuthorize("hasPermission('/stock/stockMa/remove','stock:stockMa:remove')")
    public Result batchRemove(String ids) {
        return decide(sysStockMaService.batchRemove(ids.split(",")));
    }

    /**
     * 删除均线分析
     */
    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "删除均线分析")
    @PreAuthorize("hasPermission('/stock/stockMa/remove','stock:stockMa:remove')")
    public Result remove(@PathVariable("id") String id) {
        return decide(sysStockMaService.remove(id));
    }
}
